var Items = require("./items");
var tools = require("../../tools");
var methods = {
    POST: "POST",
    GET: "GET",
    ALL: "*"
}

const WHITE_LIST = {};

var push = function (items) {
    WHITE_LIST[items.url] = items;
};

var getItems = function (url) {
    var item = undefined;
    item = WHITE_LIST[url];
    if (!item) {
        for (var key in WHITE_LIST) {
            if (tools.wildcard(key, url)) {
                item = WHITE_LIST[key];
                break;
            }
        }
    }
    return item;
};

var ifPass = function (method, url) {
    var item = undefined;
    if (url && (item = getItems(url))) {
        return item.method === methods.ALL || item.method.toLocaleUpperCase() === method.toLocaleUpperCase();
    }
    return false;
};
push(new Items(methods.ALL, "/users/login"));

exports = module.exports = ifPass;